# coding: utf-8
from typing import List


class Solution:
    def maxAreaOfIsland(self, grid: List[List[int]]) -> int:
        res = 0
        for i in range(len(grid)):
            for j in range(len(grid[0])):
                if(grid[i][j] == 1):
                    res = max(self.dfs(grid,i,j),res)
        return res

    # 使用dfs
    def dfs(self, grid: List[List[int]], i: int, j: int) -> int:
        if i < 0 or i >= len(grid) or j < 0 or j >= len(grid[0]) or grid[i][j] == 0:
            return 0
        else:
            grid[i][j] = 0
            count = 1
            count += self.dfs(grid, i+1, j)
            count += self.dfs(grid, i-1, j)
            count += self.dfs(grid, i, j+1)
            count += self.dfs(grid, i, j-1)
            return count


if __name__ == '__main__':
    solu = Solution()

    # print(solu.isMatch('ab', 'aab'))
